package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/*
在demo表中添加一条数据
 */

public class JDBCUtil_2 {

    public static void main(String[] args) {
        Statement stmt = null;
        Connection conn = null;
        try {
            //regist SQL Driver
            Class.forName("com.mysql.cj.jdbc.Driver");
            //Define SQL statement
            String sql = "insert into demo values(null,'005','男','江西理工','伍六七','123456')";
            //Access to the object

            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/sanqiansql?serverTimezone=GMT&", "root", "shaozhaoming");
            //
            stmt = conn.createStatement();
            int count = stmt.executeUpdate(sql);//row
            System.out.println(count);
            if(count >0 ){
                System.out.println("添加成功");
            }else{
                System.out.println("添加失败");
            }
         } catch (SQLException e) {
                e.printStackTrace();
         } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        finally {
            if(stmt != null){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(conn != null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
